<template>
	<div>
		<view v-if="$check_register_field('add','full_name','/ordinary_users/view')" class="col-12 col-md-6">
			<view class="diy_title">
				<text>姓名:
				</text>
			</view>
			<!-- 文本 -->
			<view class="diy_field diy_text">
				<input type="text" id="form_full_name" v-model="form['full_name']" placeholder="请输入姓名" />
			</view>
		</view>
		<view v-if="$check_register_field('add','gender','/ordinary_users/view')" class="col-12 col-md-6">
			<view class="diy_title">
				<text>性别:
				</text>
			</view>
			<!-- 选项 -->
			<view class="diy_field diy_down">
				<select id="form_gender" v-model="form['gender']">
					<option v-for="o in list_gender" :value="o">
						{{o}}
					</option>
				</select>
			</view>
		</view>
		<view v-if="$check_register_field('add','age','/ordinary_users/view')" class="col-12 col-md-6">
			<view class="diy_title">
				<text>年龄:
				</text>
			</view>
			<!-- 文本 -->
			<view class="diy_field diy_text">
				<input type="text" id="form_age" v-model="form['age']" placeholder="请输入年龄" />
			</view>
		</view>
	</div>
</template>

<script>
	export default {
		model: {
			prop: "form",
			event: "change"
		},
		props: {
			form: {
				type: Object,
				default: ()=>{
					return {
						url_upload: "~/api/ordinary_users/upload?",
					}
				}
			}
		},
		data(){
			return {
				"list_gender": ['男','女'],
			}
		},
		methods: {
			/**
			 * 上传图片
			 * @param {Object} param文件参数
			 */
			change_img(key_name){
				console.log(11111)
				var _self = this;
				// 选择图像方法
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						const tempFilePaths = res.tempFilePaths;
						const uploadTask = uni.uploadFile({
							url: _self.$fullUrl('/api/ordinary_users/upload?'),
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'i_want_to_customize': 'test'
							},
							header: {
								'x-auth-token': "null"
							},
							success: function(uploadFileRes) {
								var filename = JSON.parse(uploadFileRes.data).result.url
								_self.$delete(_self.form,key_name);
								_self.$set(_self.form,key_name,filename);
								console.log(_self.form[key_name])
							}
						});

						uploadTask.onProgressUpdate(function(res) {
							_self.percent = res.progress;
							console.log('上传进度' + res.progress);
							console.log('已经上传的数据长度' + res.totalBytesSent);
							console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
						});
					},
					error: function(e) {
						console.log(e);
					}
				});
			},
		},
		onLoad(){
		}
	}
</script>

<style>
.col-md-6{
	display: flex;
	margin-bottom: 1.25rem;
	height: 36px;
}
.diy_title{
	/* flex: 1.2; */
	display: inline-block;
	width: 5.0625rem;
	margin-right: 0.3125rem;
	font-size: 0.875rem;
    color: #333;
		padding-top: 0.3125rem;
}
.diy_field{
	/* flex: 5; */
	display: inline-block;
	width: 100%;
	background: #ffffff;
	height: 2.25rem;
	line-height:  2.25rem;
	border-radius: 0.25rem;
	padding-left: 0.625rem;


	}
	.diy_field input{
		display: inline;
		font-size: 0.875rem;
	}
</style>
